package item.inkcloud.shopservice.service;

import item.inkcloud.shopservice.feignClient.UserServiceFeignClient;
import item.inkcloud.shopservice.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class ProductService {

    @Autowired
    ProductMapper productMapper;

    @Autowired
    EmailService emailService;

    @Autowired
    UserServiceFeignClient userServiceFeignClient;

    public int order(String userid, String productName) {
        try {
            HashMap userInfo = userServiceFeignClient.getUserInfo(userid);
            HashMap userData =(HashMap) userInfo.get("data");

            String username =(String) userData.get("username");
            String email = (String) userData.get("email");


             emailService.email(username, email, productName);

            return 1;
        }catch (Exception e){
            return 0;
        }
    }

    public List productList(){
        List list = new ArrayList(productMapper.findAll());
        return list;
    }

}

